package com.itheima.servlet;

import com.itheima.bean.Student;
import com.itheima.dao.AddStudent;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addStudentServlet")
public class AddStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取数据
        String username = req.getParameter("username");
        String age = req.getParameter("age");
        String score = req.getParameter("score");
        //创建学生对象并且赋值
        AddStudent as=new AddStudent();
        as.addStudent(username,age,score);
        //页面的跳转
        resp.getWriter().write("添加成功，页面将会在两秒后跳转到首页......");
        resp.setHeader("refresh", "2;URL=/stu/index.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
